package cn.xcstudenth.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;

import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;
import java.util.List;

import cn.xcstudenth.myapplication.adapter.MyPagerAdapter;
import cn.xcstudenth.myapplication.fragment.MathViewHtmlFragment;
import cn.xcstudenth.myapplication.fragment.RichTextViewFragment;
import cn.xcstudenth.myapplication.fragment.TextViewHtmlFragment;
import cn.xcstudenth.myapplication.fragment.WebViewHtmlFragment;

public class MainActivity extends AppCompatActivity {

    String tex   = "This come from string. You can insert inline formula:" +
            " \\(ax^2 + bx + c = 0\\) " +
            "or displayed formula: $$\\sum_{i=0}^n i^2 = \\frac{(n^2+n)(2n+1)}{6}$$";
    String two   = "<p>解：<span class=\\\"ql-formula\\\" data-value=\\\"\\\\left(2a\\\\right)^3.A=8a^5\\\\\\\\\\\\;8a^3.A=8a^5\\\\\\\\A=8a^5\\\\div8a^3\\\\\\\\A=a^2\\\">$$\\\\left(2a\\\\right)^3.A=8a^5\\\\\\\\\\\\;8a^3.A=8a^5\\\\\\\\A=8a^5\\\\div8a^3\\\\\\\\A=a^2$$</span> ． </p> \\n\\r<p>故选A．</p> \\n\\r<p>先计算积的乘方，再根据单项式乘以单项式的逆运算即可．</p> \\n\\r<p>本题考查了单项式乘以单项式，解题的关键是注意字母指数的变化．</p>";
    String three = "<div>在边长为a的正方形中挖去一个边长为b的小正方形（a＞b）（如图甲），把余下的部分拼成一个矩形（如图乙），" +
            " \\(ax^2 + bx + c = 0\\) " +
            "or displayed formula: $$\\sum_{i=0}^n i^2 = \\frac{(n^2+n)(2n+1)}{6}$$" +
            "根据两个图形中阴影部分的面积相等，可以验证（　　）</div><div><img src=\"http://xcimg.zhuocan.com.cn/02/201809/2/20181005094844775728.png\"><br></div>";



    private static final String richText =
            "<html><head><title>TextView也会解析Title的内容</title></head><body>"
                    + "<p style=\"color: red;\">TextView支持的标签:</p>"
                    + "<p><strong>强调</strong>&nbsp;&nbsp;&nbsp;&nbsp;<em>斜体</em>&nbsp;&nbsp;&nbsp;&nbsp;"
                    + "正常字体<sup>上标</sup><sub>下标</sub>&nbsp;&nbsp;&nbsp;&nbsp;<u>带有下划线字体</u></p>"
                    + "<p><a href=\"http://www.baidu.com/xhtml/\">超链接HTML入门</a>学习HTML! 学习HTML! 学习HTML! 学习HTML!</p>"
                    + "<h1>标题1</h1><h6>标题6</h6>"
                    + "<p><font color=\"#00bbaa\">颜色1</font>&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"#aabb00\">颜色2</font></p>"
                    + "<p style=\"color: red;\">TextView不支持的标签样式:</p>"
                    + "<p><font color=\"rgb(255, 0, 0)\">颜色rgb的差异</font>&nbsp;&nbsp;"
                    + "<font size=\"1\">font-size的差异</font>&nbsp;&nbsp;"
                    + "<font face=\"Times New Roman, verdana, arial,sans-serif, SimKai\">font-family的差异</font></p>"
                    + "<p><img src=\"http://avatar.csdn.net/0/3/8/2_zhang957411207.jpg\"/></p>"
                    + "<p><img src=\"http://test.img.huaguosun.com/images/MarketingCampaign/1545792379256.jpg\"/></p>"
                    + "<p><img src=\"http://test.img.huaguosun.com/images/MarketingCampaign/1545792379256.jpg\"/></p>"
                    + "<p><img src=\"http://test.img.huaguosun.com/images/MarketingCampaign/1545792379256.jpg\"/></p>"
                    + "<p><img src=\"http://pic36.photophoto.cn/20150708/0012025199649765_b.jpg\"/></p>"
                    + "<p><img src=\"http://test.img.huaguosun.com/images/MarketingCampaign/1545792379256.jpg\"/></p>"
                    + "<p><img src=\"http://pic41.nipic.com/20140519/18505720_094740582159_2.jpg\"/></p>"
                    + "<p><img src=\"http://pic6.photophoto.cn/20080311/0034034854076462_b.jpg\"/></p>"
                    + "<p><img src=\"http://avatar.csdn.net/0/3/8/2_zhang957411207.jpg\"/></p>"
                    + "<p><img src=\"http://test.img.huaguosun.com/images/MarketingCampaign/1545792379262.jpg\"/></p></body></html>";

    private List<String>     mList      = new ArrayList<>();
    private List<String>     mTitleList = new ArrayList<>();
    private List<Fragment>   mFragments = new ArrayList<>();
    private SlidingTabLayout mSlidingTable;
    private ViewPager        mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mSlidingTable = (SlidingTabLayout) findViewById(R.id.sliding_tablayout);
        mViewPager    = (ViewPager) findViewById(R.id.viewpager);


        mList.add(tex);
        mList.add(two);
        mList.add(three);
        mList.add(richText);

        mTitleList.add("普通的textView加载html");
        mTitleList.add("普通的WebView加载html");
        mTitleList.add("RichTextView加载html");
        mTitleList.add("MathView加载html");

        mFragments.add(new TextViewHtmlFragment(mList));
        mFragments.add(new WebViewHtmlFragment(mList));
        mFragments.add(new RichTextViewFragment(mList));
        mFragments.add(new MathViewHtmlFragment(mList));

        MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager(),0, mFragments, mTitleList);
        mViewPager.setAdapter(adapter);
        mSlidingTable.setViewPager(mViewPager);

    }
}
